package sunwin.yoms.web.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import sunwin.yoms.comm.YomsException;
import sunwin.yoms.comm.YomsFunction;
import sunwin.yoms.comm.YomsPage;
import sunwin.yoms.domain.system.AdminLoginLogDomain;
import sunwin.yoms.service.system.AdminLoginLogService;
import sunwin.yoms.web.comm.R;
import sunwin.yoms.web.comm.YomsController;

import java.util.List;

/**
 * Created by watson on 2015/10/30.
 */
@Controller
public class AdminLoginLogController {
    @Autowired
    private AdminLoginLogService adminLoginLogService;
    private final String FindLoginLog = "system/loginLog.find";

    @RequestMapping(value = R.AdminLoginLog, method = RequestMethod.GET)
    @YomsController(functionNo = YomsFunction.FindAdminLoginLog, viewName = FindLoginLog)
    public ModelAndView getLoginLog(AdminLoginLogDomain adminLoginLogDomain,
                                    @RequestParam(required = false, defaultValue = "1") int pageIndex,
                                    ModelMap modelMap)throws YomsException{
        modelMap.addAttribute("adminLoginLogDomain",adminLoginLogDomain);
        YomsPage yomsPage=new YomsPage();
        yomsPage.setPageIndex(pageIndex);
        List<AdminLoginLogDomain> domains=adminLoginLogService.getAdminLoginLog(adminLoginLogDomain,yomsPage);
        ModelAndView mav=new ModelAndView();
        mav.addObject("yomsPage", yomsPage);
        mav.addObject("logs",domains);
        return mav;
    }
}
